//    Copyright (C) Kherty.  All rights reserved.
namespace OpenLS.Spreadsheet
{
    public struct CellRelativeAddress
    {
        public CellRelativeAddress(CellAddress target, CellAddress source)
        {
            Row = target.Row - source.Row;
            Column = target.Column - source.Column;
        }
        public CellRelativeAddress(int row, int column)
        {
            Row = row;
            Column = column;
        }
        public static CellRelativeAddress operator +(CellRelativeAddress a, CellRelativeAddress b)
        {
            return new CellRelativeAddress(a.Row + b.Row, a.Column + b.Column);
        }
        public static CellRelativeAddress operator -(CellRelativeAddress a, CellRelativeAddress b)
        {
            return new CellRelativeAddress(a.Row - b.Row, a.Column - b.Column);
        }
        public override string ToString()
        {
            return "row = " + Row + " column = " + Column;
        }
        public override int GetHashCode()
        {
            return Row << 16 + Column;
        }
        public override bool Equals(object obj)
        {
            var address = (CellRelativeAddress)obj;
            return address.Row == Row && address.Column == Column;
        }
        public readonly int Row, Column;


        internal bool IsZero
        {
            get
            {
                return Row == 0 && Column == 0;
            }
        }
    }
}
